package com.jiangxjsy.model.crm.bo;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.jiangxjsy.core.enums.FieldSearchEnum;
import com.jiangxjsy.core.page.PageCriteria;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.elasticsearch.script.Script;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * wukong-crm-master
 * 蒋胜宇
 * 2025/6/20 15:24
 */

@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CrmSearchBO extends PageCriteria implements Serializable {
    /**
     * 搜索条件
     */
    private String search;

    /**
     * 公海ID
     */
    private Integer poolId;

    /**
     * 场景ID
     */
    private Integer sceneId;

    /**
     * type
     */
    private Integer label;

    /**
     * 排序字段
     */
    private String sortField;

    /**
     * 排序字段 1 倒序 2 正序
     */
    private Integer order;

    /**
     * 高级筛选列表
     */
    private List<Search> searchList = new ArrayList<>();

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Search implements Serializable {
        /**
         * 名字
         */
        private String name;

        /**
         * 格式
         */
        private String formType;

        /**
         * 高级筛选列表
         */
        @JsonProperty("type")
        private FieldSearchEnum searchEnum;

        /**
         * 脚本查询需要
         */
        private transient Script script;

        /**
         * 值列表
         */
        private List<String> values = new ArrayList<>();


        public Search setScript(Script script) {
            this.script = script;
            return this;
        }

        public Search(String name, String formType, FieldSearchEnum searchEnum, List<String> values) {
            this.name = name;
            this.formType = formType;
            this.searchEnum = searchEnum;
            this.values = values;
        }

        public Search(String name, String formType, FieldSearchEnum searchEnum) {
            this.name = name;
            this.formType = formType;
            this.searchEnum = searchEnum;
        }
    }
}
